home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000166_icon-group-sender_Thu Nov 8 16:50:37 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id fA8NnBA06365
  4.     for icon-group-addresses; Thu, 8 Nov 2001 16:49:11 -0700 (MST)
  5. Message-Id: <200111082349.fA8NnBA06365@baskerville.CS.Arizona.EDU>
  6. Date: Thu, 08 Nov 2001 14:08:12 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: Taybin Rutkin <trutkin@physics.clarku.edu>
  10. CC: icon-group@cs.arizona.edu
  11. Subject: Re: mutual evaluation
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 2300
  15.  
  16. Taybin Rutkin wrote:
  17. > On Thu, 8 Nov 2001, Steve Wampler wrote:
  18. > > The idiom in use in these mutual evaluation examples is simple:
  19. > >
  20. > >    return 2(initialize, compute, cleanup)
  21. > >
  22. > > which is really pretty clean - most of the time.  It's not clean
  23. > > when any of initialize, compute, or cleanup is complex (but *that*
  24. > > can often be solved by encapsulating the complex action in a
  25. > > procedure).
  26. > Is 2() a standard library procedure?  I don't think I've seen it
  27. > before.  I didn't know that procedures could have a digit as a name.  How
  28. > does it work?
  29.  
  30. Ah, mutual evaluation is an Icon language expression evaluation feature, not a
  31. procedure.  It's covered starting on page 72 of the 3rd ed. of the Icon
  32. programming language (and probably appears in all the earlier books - it's been
  33. around a while... look for mutual evaluation in the index).  It actually helps
  34. illustrate how general Icon's expression evaluation mechanims is.
  35.  
  36. The expression syntax:
  37.  
  38.     expr0(expr1,expr2,...,exprN)
  39.  
  40. has a couple of uses.  If expr0 evaluates to a function or procedure name
  41. then that function/procedure is invoked (after evaluating the arguments
  42. of course!).  If expr0 evaluates to an integer, then the arguments are
  43. evaluated and the whole expression returns the result produced by the argument
  44. in the position represented by that integer.  [Since expr0 evaluates to
  45. a "position", 0 means to produce the result of the last argument and
  46. omitting expr0 defaults it to 0.]
  47.  
  48. So, for example:
  49.  
  50.    write( 1("a","b","c") )
  51.  
  52. would output "a", while
  53.  
  54.    write( 3("a","b","c") )
  55.  
  56. would output "c", and
  57.  
  58.    write( ("a","b","c") )
  59.  
  60. also outputs "c".
  61.  
  62. Naturally, being Icon, any/all of the expressions can be
  63. arbitrarily complex.  For example, there's nothing other
  64. than a programmer's common sense keeping expr0 be
  65. a generator that produces both integers *and* function/
  66. procedure names... (very hard to think of a valid use for
  67. that one!)
  68.  
  69. As an aside, it might have been cleaner if I had written:
  70.  
  71.    return 3(f := open(fName), seek(f,0), where(f)-1, close(f))
  72.  
  73. instead of
  74.  
  75.    return 2(f := open(fName), where(seek(f,0))-1, close(f))
  76.  
  77. in the previous message, since the first more clearly shows
  78. the steps involved.
  79.  
  80.  
  81. --
  82. Steve Wampler-  SOLIS Project, National Solar Observatory
  83. swampler@noao.edu
  84.